const sql = require("../models/db");
const ErrorInfo = require("../models/error.model.js");

exports.create = (req, res, errorEntity) => {

  return new Promise((resolve, reject)=>{
  // Validate request
    if (!req.body) {
      res.status(400).send({
        message: "Content can not be empty!"
      });
      reject("Content can not be empty!")
      return;
    }

    // Create a Tutorial
    const errorInfo = new ErrorInfo({...errorEntity});

    sql.query("INSERT INTO error_info SET ?", errorInfo, (err, sqlres) => {
      if (err) {
        res.status(500).send({
          message: "SQL error!"
        });
        reject(err)
        return;
      } else {
        resolve(errorInfo)
      }
    });
  })

};